--- 战策十一·调兵遣将
local policy11 = fk.CreateSkill {
    name = "move_people",
    tgas = { Skill.Compulsory },
    dynamic_name = function (self, player, lang)
      return player == Self and self.name or "unknownpolicy"
    end,
    dynamic_desc = function (self, player, lang)
      return player == Self and self.name or "unknownpolicy"
    end,
}

Fk:loadTranslationTable {
    ["@[move_people_mark]"] = "调兵遣将",
    ["move_people_ask"] = "战策-调兵遣将：你可以与一名与你势力相同的角色交换副将",

}

local H = require "packages/ol_hegemony/util"
local HG = require "packages/new_heg_diy_my/util"

policy11:addEffect(fk.EventPhaseStart, {
    can_trigger = function(self, event, target, player, data)
        local mark_name = "@[private]" .. policy11.name .. "_mark"
        return player:getMark(mark_name) ~= 0 and target == player and player.phase == Player.Finish
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local targets = table.filter(room.alive_players, function(p)
            return H.compareKingdomWith(p, player)
        end)
        local tos = room:askToChoosePlayers(player, {
            targets = targets,
            min_num = 1,
            max_num = 1,
            prompt = "move_people_ask",
            skill_name = "unknownpolicy",
            cancelable = true,
        })
        if #tos > 0 then
            event:setCostData(self, { tos = tos })
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local mark_name = "@[private]" .. policy11.name .. "_mark"
        local to = event:getCostData(self).tos[1]
        if to ~= player then
            HG.SwapTwoPlayersDeputy(room, player, to)
        end
        room:setPlayerMark(player, mark_name, 0)
        room:handleAddLoseSkills(player, "-move_people", nil, false)
        room.logic:trigger(HG.HegLosePolicy, player, { player, policy11.name })
    end,
})

return policy11
